package com.tqjc.common.faulthandle.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tqjc.common.faulthandle.entity.FaultRecord;
import com.tqjc.common.faulthandle.mapper.FaultRecordMapper;
import com.tqjc.common.faulthandle.service.FaultRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;

/**
 * @projectName: BaotouSteel
 * @className: FaultRecordServiceImpl
 * @author: Patienyon
 * @description: TODO
 * @date: 2023-07-04 16:20
 */
@DS("baotou")
@Service
public class FaultRecordServiceImpl extends ServiceImpl<FaultRecordMapper, FaultRecord> implements FaultRecordService {

    @Resource
    FaultRecordMapper faultRecordMapper;
    @Override
    public List<Map<String, Integer>> getFaultTypeAndCountByParams(String craneType, String workMode, Timestamp beginTime, Timestamp endTime, String fuzzyMapper) {
        return faultRecordMapper.getFaultTypeAndCountByParams(craneType, workMode, beginTime, endTime, fuzzyMapper);
    }

    @Override
    public boolean isExistInfo(FaultRecord faultRecord) {
        new Timestamp(System.currentTimeMillis());
        int res = faultRecordMapper.selectCount(new LambdaQueryWrapper<FaultRecord>()
                .eq(FaultRecord::getAdditionInfo, faultRecord.getAdditionInfo())
                .eq(FaultRecord::getCraneType,faultRecord.getCraneType())
                .ge(FaultRecord::getMeetTime, LocalDateTime.now().minusMinutes(8L)));

        return res > 0;
    }

}
